﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace FoobarFootball.Models.MatchStates
{
    public class Pass : MatchState
    {
        private static MatchState state = new Pass();

        private Pass()
        {
        }

        public static MatchState Instance()
        {
            return state;
        }

        public override void Turn(MatchEngine matchEngine)
        {
            // Set players involved in this turn
            matchEngine.Ball.CurrentPosition = matchEngine.Ball.FuturePosition;
            matchEngine.AttackingTeam.PlayerInPossession = matchEngine.AttackingTeam.SupportingPlayer;
            matchEngine.DefendingTeam.ChallengingPlayer = matchEngine.DefendingTeam.ChallengingPlayer;

            // Move players involved with this turn
            matchEngine.AttackingTeam.PlayerInPossession.MovePlayer(matchEngine.AttackingTeam.PlayerInPossession.CurrentPosition, matchEngine.Ball.CurrentPosition);
            matchEngine.DefendingTeam.ChallengingPlayer.MovePlayer(matchEngine.DefendingTeam.ChallengingPlayer.CurrentPosition, matchEngine.Ball.CurrentPosition);

            // Commentery
            matchEngine.Commentry.Add("Joe Cole passes the ball forward");

            // Change the future position of the ball and the intended target.
            matchEngine.Ball.FuturePosition = matchEngine.Pitch.Six;

            ChangeState(matchEngine, FinalWhistle.Instance());
        }
    }
}
